package com.ruoyi.doorcontrol.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.doorcontrol.domain.ThFaceRecords;
import com.ruoyi.doorcontrol.service.IThFaceRecordsService;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 记录 后期可以删掉写在各自的记录中
 */
@RestController
@RequestMapping("/doorlock/control")
public class ThRecordsController extends BaseController {

    @Autowired
    private IThFaceRecordsService thFaceRecordsService;

    @PostMapping("/getList2")
    public String getList2(@RequestBody Map<String,Object> map){
        HttpServletRequest request = ServletUtils.getRequest();
        String ipAddress = HttpUtils.getIpAddress(request);
        /*if(null == ipAddress){
            throw new CustomException("获取请求的ip失败！");
        }else if(!serverip.contains(ipAddress)){
            System.out.println(serverip+"门禁中来自服务器的请求地址是："+ipAddress);
            throw new CustomException("请求地址错误！");
        }*/
        List<ThFaceRecords> list = null;
        ThFaceRecords thFaceRecords = JSON.parseObject(JSON.toJSONString(map.get("yiVisitControl")), ThFaceRecords.class);
        startPage2(thFaceRecords.getPageNum(),thFaceRecords.getPageSize());
        if(thFaceRecords.getUserType().equals("0")){
            list = thFaceRecordsService.selectYiVisitControlList2(thFaceRecords);//访客的
        }else {
            list = thFaceRecordsService.selectYiVisitControlListByyg(thFaceRecords);//员工的 员工的编号和sys-user表未关联
        }
        TableDataInfo dataTable = getDataTable(list);
        String jsonString = JSONObject.toJSONString(dataTable);
        return jsonString;
    }


}
